package com.dingup.paike.service.message.impl;

import com.dingtalk.api.response.OapiMessageCorpconversationAsyncsendV2Response;
import com.dingup.api.Util.DateUtil;
import com.dingup.api.enums.ThirdPartyTypeEnum;
import com.dingup.api.template.message.bean.msg.DingTalkActionCardBean;
import com.dingup.api.template.message.bean.msg.DingTalkTextBean;
import com.dingup.api.template.message.bean.msg.MarkdownUtil;
import com.dingup.api.template.message.util.DingTalkConstUtil;
import com.dingup.api.template.message.util.DingTalkMessageUtil;
import com.dingup.paike.adapter.pk.PkLessonInfoAdapter;
import com.dingup.paike.dao.PkLessonUserMapper;
import com.dingup.paike.dao.PkMessageDetailsMapper;
import com.dingup.paike.enums.MessageTypeEnum;
import com.dingup.paike.enums.MessageUserIdentityEnum;
import com.dingup.paike.enums.PkLessonUserTypeEnum;
import com.dingup.paike.feign.client.classInfo.ClassInfoFeignClient;
import com.dingup.paike.model.message.PkMessageDetails;
import com.dingup.paike.model.pk.PkLessonInfo;
import com.dingup.paike.model.pk.PkLessonUser;
import com.dingup.paike.service.message.DingTalkMsgService;
import com.dingup.paike.util.ConstUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;

/**
 * Created by wancheng on 2018/10/16.
 */
@Service
public class DingTalkMsgServiceImpl implements DingTalkMsgService {

    private static final String SEND_MSG_BEFORE_CLASS_URL = "";
    private static final String IMAGE_URL = "";
    private static final String MSG_BEFORE_CLASS_AT_YESTERDAY_FOR_TEACHER = "%s/teacher/notice/%s/%s";
    private static final String MSG_BEFORE_CLASS_AT_YESTERDAY_FOR_MASTER = "%s/head/remind/%s/%s";
    private static final String MSG_BEFORE_LESSON_FOR_TEACHER = "%s/going/class/%s";
    private static final String MSG_BEFORE_LESSON_FOR_MASTER = "%s/signin/%s";
    private static final String MSG_ELEMENT_CONTAINER_FOR_MASTER = "%s/signlist/%s/%s";
    private static final String MSG_CONFIRM_CLASS_HOUR_FOR_MASTER = "%s/class/confirm/%s";
    private static final String URL_TEACHER = "%s/class/content/%s/%s";
    private static final String URL_CLASS_TEACHER = "%s/feedview/%s";
    private static final String URL_HOMEWORK_FINISH = "dingtalk://dingtalkclient/page/link?url=%s&pc_slide=true";
    private static final String URL_HOMEWORK_FINISH_REDIRECT_URL = "%s/correcting";
    private static final String URL_E_LOGIN = "https://oapi.dingtalk.com/connect/oauth2/sns_authorize?appid=%s&response_type=code&scope=snsapi_auth&state=STATE&redirect_uri=%s/manageIndex";
    private static Logger logger = LoggerFactory.getLogger(DingTalkMsgServiceImpl.class);

    @Autowired
    PkMessageDetailsMapper pkMessageDetailsMapper;
    @Autowired
    ClassInfoFeignClient classInfoFeignClient;
    @Autowired
    PkLessonUserMapper pkLessonUserMapper;

    @Override
    @Async
    public void sendMsgBeforeClassAtYesterdayForTeacher(String teacherId, String teacherName, List<Integer> pkLessonIds) {
        try {
            String pkMessageDetailsId = UUID.randomUUID().toString();
            String url = String.format(MSG_BEFORE_CLASS_AT_YESTERDAY_FOR_TEACHER, ConstUtil.SYS_CONFIG_DATA.getInnerDomainName(), teacherId, pkMessageDetailsId);
            DingTalkActionCardBean actionCardBean = new DingTalkActionCardBean();
            actionCardBean.setTitle("上课提醒");
            actionCardBean.setAgentId(DingTalkConstUtil.XINIAO_AGENT_ID);
            actionCardBean.setUserIds(teacherId);
            actionCardBean.setSingleTitle("查看详情");
            actionCardBean.setSingleUrl(url);
            String markdown = MarkdownUtil.getMarkdown(
                    MarkdownUtil.getImage(IMAGE_URL),
                    MarkdownUtil.getTitle("上课提醒", 5),
                    MarkdownUtil.getTitle("你明天有 " + pkLessonIds.size() + " 节课要上", 0),
                    MarkdownUtil.getTitle("请点击查看详情，及时确认收到消息", 6)
            );
            actionCardBean.setMarkdown(markdown);
            OapiMessageCorpconversationAsyncsendV2Response response = DingTalkMessageUtil.sendActionCardMsg(actionCardBean);
            Boolean ifSendSuccess = false;
            if (response.getErrcode() == 0) {
                ifSendSuccess = true;
            }
            PkMessageDetails pkMessageDetails = getPkMessageDetails(teacherId, teacherName, true, pkLessonIds);
            pkMessageDetails.setId(pkMessageDetailsId);
            pkMessageDetails.setIfSendSuccess(ifSendSuccess);
            pkMessageDetails.setMessageContent("上课提醒:" + "你明天有 " + pkLessonIds.size() + " 节课要上");
            pkMessageDetails.setMessageUrl(url);
            pkMessageDetails.setMessageType(MessageTypeEnum.MESSAGE_CLASS_INFLATED);
            pkMessageDetailsMapper.insertSelective(pkMessageDetails);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    @Async
    public void sendMsgBeforeClassAtYesterdayForMaster(String masterId, String masterName, List<Integer> pkLessonIds) {
        try {
            String pkMessageDetailsId = UUID.randomUUID().toString();
            String url = String.format(MSG_BEFORE_CLASS_AT_YESTERDAY_FOR_MASTER, ConstUtil.SYS_CONFIG_DATA.getInnerDomainName(), masterId, pkMessageDetailsId);
            DingTalkActionCardBean actionCardBean = new DingTalkActionCardBean();
            actionCardBean.setTitle("上课提醒");
            actionCardBean.setAgentId(DingTalkConstUtil.XINIAO_AGENT_ID);
            actionCardBean.setUserIds(masterId);
            actionCardBean.setSingleTitle("查看详情");
            actionCardBean.setSingleUrl(url);
            String markdown = MarkdownUtil.getMarkdown(
                    MarkdownUtil.getImage(IMAGE_URL),
                    MarkdownUtil.getTitle("上课提醒", 5),
                    MarkdownUtil.getTitle("你明天有 " + pkLessonIds.size() + " 节课要上", 0),
                    MarkdownUtil.getTitle("请点击查看详情查看老师/学生确认情况", 6)
            );
            actionCardBean.setMarkdown(markdown);
            OapiMessageCorpconversationAsyncsendV2Response response = DingTalkMessageUtil.sendActionCardMsg(actionCardBean);
            Boolean ifSendSuccess = false;
            if (response.getErrcode() == 0) {
                ifSendSuccess = true;
            }
            PkMessageDetails pkMessageDetails = getPkMessageDetails(masterId, masterName, false, pkLessonIds);
            pkMessageDetails.setId(pkMessageDetailsId);
            pkMessageDetails.setIfSendSuccess(ifSendSuccess);
            pkMessageDetails.setMessageContent("上课提醒" + "你明天有 " + pkLessonIds.size() + " 节课要上");
            pkMessageDetails.setMessageUrl(url);
            pkMessageDetails.setMessageType(MessageTypeEnum.MESSAGE_CLASS_INFLATED);
            pkMessageDetailsMapper.insertSelective(pkMessageDetails);
        } catch (Exception e) {

        }
    }


    @Override
    @Async
    public void sendMsgBeforeTenMinute(PkLessonUser user, String className, MessageTypeEnum type, PkLessonInfoAdapter pkLessonInfoAdapter) {
        try {
            String lessonType = "";
            if (pkLessonInfoAdapter.getIfOnlineLesson()) {
                lessonType = "ClassIn";
            } else {
                lessonType = "线下课";
            }
            String subject = pkLessonInfoAdapter.getSubjectName();
            String day = DateUtil.date2Str(pkLessonInfoAdapter.getBeginTime(), "MM月dd日");
            String begin = DateUtil.date2Str(pkLessonInfoAdapter.getBeginTime(), "HH:mm");
            String end = DateUtil.date2Str(pkLessonInfoAdapter.getEndTime(), "HH:mm");
            String lessonMsg = subject + " " + day + " " + begin + "~" + end;
            String timeContent = "";
            if (MessageTypeEnum.MESSAGE_CLASS_BEFORE_ONE_HOUR.equals(type)) {
                timeContent = "1小时";
            } else if (MessageTypeEnum.MESSAGE_CLASS_CLASS_IN.equals(type)) {
                timeContent = "20min";
            }
            Boolean ifTeacher = false;
            String url = "";
            String content = "";
            if (PkLessonUserTypeEnum.TEACHER.equals(user.getType())) {
                ifTeacher = true;
                content = "还有" + timeContent + "就要上课啦，请提前进入教室做做好准备工作";
                url = String.format(MSG_BEFORE_LESSON_FOR_TEACHER, ConstUtil.SYS_CONFIG_DATA.getInnerDomainName(), pkLessonInfoAdapter.getId());
            } else {
                content = "还有" + timeContent + "就要上课啦，请提醒老师和学生提前进入教室,做好签到工作";
                url = String.format(MSG_BEFORE_LESSON_FOR_MASTER, ConstUtil.SYS_CONFIG_DATA.getInnerDomainName(), pkLessonInfoAdapter.getId());
            }
            String pkMessageDetailsId = UUID.randomUUID().toString();
            DingTalkActionCardBean actionCardBean = new DingTalkActionCardBean();
            actionCardBean.setTitle("上课提醒");
            actionCardBean.setAgentId(DingTalkConstUtil.XINIAO_AGENT_ID);
            actionCardBean.setUserIds(user.getUserId());
            if (ifTeacher) {
                actionCardBean.setSingleTitle("查看详情");
            } else {
                actionCardBean.setSingleTitle("查看学生签到情况");
            }
            actionCardBean.setSingleUrl(url);
            String markdown = MarkdownUtil.getMarkdown(
                    MarkdownUtil.getImage(IMAGE_URL),
                    MarkdownUtil.getTitle("即将上课", 5),
                    MarkdownUtil.getTitle(content, 0),
                    MarkdownUtil.getTitle(className + " " + subject, 0),
                    MarkdownUtil.getTitle(lessonMsg, 0)
            );
            actionCardBean.setMarkdown(markdown);
            OapiMessageCorpconversationAsyncsendV2Response response = DingTalkMessageUtil.sendActionCardMsg(actionCardBean);
            Boolean ifSendSuccess = false;
            if (response.getErrcode() == 0) {
                ifSendSuccess = true;
            }

            Integer[] id = {pkLessonInfoAdapter.getId()};
            PkMessageDetails pkMessageDetails = getPkMessageDetails(user.getUserId(), user.getUserName(), ifTeacher, Arrays.asList(id));
            pkMessageDetails.setId(pkMessageDetailsId);
            pkMessageDetails.setIfSendSuccess(ifSendSuccess);
            pkMessageDetails.setMessageContent(content + className + " " + lessonType + " " + lessonMsg);
            pkMessageDetails.setMessageUrl(url);
            pkMessageDetails.setMessageType(type);
            pkMessageDetailsMapper.insertSelective(pkMessageDetails);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    @Async
    public Boolean sendMsgAfterClassForTeacher(PkLessonUser teacher, PkLessonInfo lessonInfo) {
        String pkMessageDetailsId = UUID.randomUUID().toString();
        String url = String.format(URL_TEACHER, ConstUtil.SYS_CONFIG_DATA.getInnerDomainName(), lessonInfo.getId(), teacher.getUserId());
        DingTalkActionCardBean actionCardBean = new DingTalkActionCardBean();
        actionCardBean.setTitle("课堂反馈");
        actionCardBean.setAgentId(DingTalkConstUtil.XINIAO_AGENT_ID);
        actionCardBean.setUserIds(teacher.getUserId());
        actionCardBean.setSingleTitle("去填写");
        actionCardBean.setSingleUrl(url);
        String markdown = MarkdownUtil.getMarkdown(
                MarkdownUtil.getImage(IMAGE_URL),
                MarkdownUtil.getTitle("课堂反馈", 5),
                MarkdownUtil.getTitle(String.format("下课啦！请及时填写 %s 的课堂反馈", lessonInfo.getLessonName()), 0)
        );
        actionCardBean.setMarkdown(markdown);
        OapiMessageCorpconversationAsyncsendV2Response response = DingTalkMessageUtil.sendActionCardMsg(actionCardBean);
        Boolean ifSendSuccess = false;
        if (response.getErrcode() == 0) {
            ifSendSuccess = true;
        }
        Integer[] ids = {lessonInfo.getId()};
        PkMessageDetails pkMessageDetails = getPkMessageDetails(teacher.getUserId(), teacher.getUserName(), true, Arrays.asList(ids));
        pkMessageDetails.setId(pkMessageDetailsId);
        pkMessageDetails.setIfSendSuccess(ifSendSuccess);
        pkMessageDetails.setMessageContent(String.format("下课啦！请及时填写 %s 的课堂反馈", lessonInfo.getLessonName()));
        pkMessageDetails.setMessageUrl(url);
        pkMessageDetails.setMessageType(MessageTypeEnum.MESSAGE_LESSON_FEEDBACK);
        pkMessageDetailsMapper.insertSelective(pkMessageDetails);
        return ifSendSuccess;
    }


    @Override
    public Boolean sendMsgAfterClassTextForMaster(PkLessonUser master, PkLessonInfo lessonInfo) {
        String pkMessageDetailsId = UUID.randomUUID().toString();
        PkLessonUser teacher = pkLessonUserMapper.getByPkLessonIdAndType(lessonInfo.getId(), null, PkLessonUserTypeEnum.MASTER);
        DingTalkTextBean talkTextBean = new DingTalkTextBean();
        talkTextBean.setUserIds(master.getUserId());
        talkTextBean.setAgentId(DingTalkConstUtil.XINIAO_AGENT_ID);
        talkTextBean.setContent(String.format("下课啦！请提醒老师 %s 及时填写 %s 的课堂反馈", teacher.getUserName(), lessonInfo.getLessonName()));
        OapiMessageCorpconversationAsyncsendV2Response response = DingTalkMessageUtil.sendTextMsg(talkTextBean);
        Boolean ifSendSuccess = false;
        if (response.getErrcode() == 0) {
            ifSendSuccess = true;
        }
        Integer[] ids = {lessonInfo.getId()};
        PkMessageDetails pkMessageDetails = getPkMessageDetails(master.getUserId(), master.getUserName(), false, Arrays.asList(ids));
        pkMessageDetails.setId(pkMessageDetailsId);
        pkMessageDetails.setIfSendSuccess(ifSendSuccess);
        pkMessageDetails.setMessageContent(String.format("下课啦！请提醒老师 %s 的课堂反馈", lessonInfo.getLessonName()));
        pkMessageDetails.setMessageType(MessageTypeEnum.MESSAGE_LESSON_FEEDBACK);
        pkMessageDetailsMapper.insertSelective(pkMessageDetails);
        return ifSendSuccess;
    }

    @Override
    public Boolean sendMsgAfterClassUrlForMaster(PkLessonUser master, PkLessonInfo lessonInfo) {
        String pkMessageDetailsId = UUID.randomUUID().toString();
        String url = String.format(URL_CLASS_TEACHER, ConstUtil.SYS_CONFIG_DATA.getInnerDomainName(), lessonInfo.getId());
        DingTalkActionCardBean actionCardBean = new DingTalkActionCardBean();
        actionCardBean.setTitle("课堂反馈");
        actionCardBean.setAgentId(DingTalkConstUtil.XINIAO_AGENT_ID);
        actionCardBean.setUserIds(master.getUserId());
        actionCardBean.setSingleTitle("查看");
        actionCardBean.setSingleUrl(url);
        String markdown = MarkdownUtil.getMarkdown(
                MarkdownUtil.getImage(IMAGE_URL),
                MarkdownUtil.getTitle("课堂反馈", 5),
                MarkdownUtil.getTitle(String.format("%s 的课堂反馈已完成", lessonInfo.getLessonName()), 0)
        );
        actionCardBean.setMarkdown(markdown);
        OapiMessageCorpconversationAsyncsendV2Response response = DingTalkMessageUtil.sendActionCardMsg(actionCardBean);
        Boolean ifSendSuccess = false;
        if (response.getErrcode() == 0) {
            ifSendSuccess = true;
        }
        Integer[] ids = {lessonInfo.getId()};
        PkMessageDetails pkMessageDetails = getPkMessageDetails(master.getUserId(), master.getUserName(), false, Arrays.asList(ids));
        pkMessageDetails.setId(pkMessageDetailsId);
        pkMessageDetails.setIfSendSuccess(ifSendSuccess);
        pkMessageDetails.setMessageContent(String.format("%s 的课堂反馈已完成", lessonInfo.getLessonName()));
        pkMessageDetails.setMessageUrl(url);
        pkMessageDetails.setMessageType(MessageTypeEnum.MESSAGE_LESSON_FEEDBACK);
        pkMessageDetailsMapper.insertSelective(pkMessageDetails);
        return ifSendSuccess;
    }

    @Override
    @Async
    public void sendMsgOfSignInForMaster(PkLessonUser user, List<Integer> pkLessonId) {
        try {
            String pkMessageDetailsId = UUID.randomUUID().toString();
            String url = String.format(MSG_ELEMENT_CONTAINER_FOR_MASTER, ConstUtil.SYS_CONFIG_DATA.getInnerDomainName(), user.getUserId(), pkMessageDetailsId);
            DingTalkActionCardBean actionCardBean = new DingTalkActionCardBean();
            actionCardBean.setTitle("签到表");
            actionCardBean.setAgentId(DingTalkConstUtil.XINIAO_AGENT_ID);
            actionCardBean.setUserIds(user.getUserId());
            actionCardBean.setSingleTitle("查看老师/学生确认情况");
            actionCardBean.setSingleUrl(url);
            String markdown = MarkdownUtil.getMarkdown(
                    MarkdownUtil.getImage(IMAGE_URL),
                    MarkdownUtil.getTitle("今天你负责的班级有" + pkLessonId.size() + "节课要上", 5),
                    MarkdownUtil.getTitle("请做好签到工作", 0)
            );
            actionCardBean.setMarkdown(markdown);
            OapiMessageCorpconversationAsyncsendV2Response response = DingTalkMessageUtil.sendActionCardMsg(actionCardBean);
            Boolean ifSendSuccess = false;
            if (response.getErrcode() == 0) {
                ifSendSuccess = true;
            }
            PkMessageDetails pkMessageDetails = getPkMessageDetails(user.getUserId(), user.getUserName(), false, pkLessonId);
            pkMessageDetails.setId(pkMessageDetailsId);
            pkMessageDetails.setIfSendSuccess(ifSendSuccess);
            pkMessageDetails.setMessageContent("签到表" + "今天你负责的班级有" + pkLessonId.size() + "节课要上");
            pkMessageDetails.setMessageUrl(url);
            pkMessageDetails.setMessageType(MessageTypeEnum.MESSAGE_ELEMENT_CONTAINER);
            pkMessageDetailsMapper.insertSelective(pkMessageDetails);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void sendMsgOfConfirmClassHourForMaster(PkLessonUser master, PkLessonInfo pkLessonInfo) {
        try {
            String pkMessageDetailsId = UUID.randomUUID().toString();
            String url = String.format(MSG_CONFIRM_CLASS_HOUR_FOR_MASTER, ConstUtil.SYS_CONFIG_DATA.getInnerDomainName(), pkLessonInfo.getId());
            DingTalkActionCardBean actionCardBean = new DingTalkActionCardBean();
            actionCardBean.setTitle("确认课时");
            actionCardBean.setAgentId(DingTalkConstUtil.XINIAO_AGENT_ID);
            actionCardBean.setUserIds(master.getUserId());
            actionCardBean.setSingleTitle("查看详情");
            actionCardBean.setSingleUrl(url);
            String markdown = MarkdownUtil.getMarkdown(
                    MarkdownUtil.getImage(IMAGE_URL),
                    MarkdownUtil.getTitle("确认课时", 5),
                    MarkdownUtil.getTitle("下课啦!请为" + pkLessonInfo.getLessonName() + "确认课时", 0),
                    MarkdownUtil.getTitle("如果课节信息与实际情况不符,请联系教务老师修改后确认", 6)
            );
            actionCardBean.setMarkdown(markdown);
            OapiMessageCorpconversationAsyncsendV2Response response = DingTalkMessageUtil.sendActionCardMsg(actionCardBean);
            Boolean ifSendSuccess = false;
            if (response.getErrcode() == 0) {
                ifSendSuccess = true;
            }
            Integer[] ids = {pkLessonInfo.getId()};
            PkMessageDetails pkMessageDetails = getPkMessageDetails(master.getUserId(), master.getUserName(), false, Arrays.asList(ids));
            pkMessageDetails.setId(pkMessageDetailsId);
            pkMessageDetails.setIfSendSuccess(ifSendSuccess);
            pkMessageDetails.setMessageContent("下课啦!请为" + pkLessonInfo.getLessonName() + "确认课时");
            pkMessageDetails.setMessageUrl(url);
            pkMessageDetails.setMessageType(MessageTypeEnum.MESSAGE_LESSON_CONFIRM);
            pkMessageDetailsMapper.insertSelective(pkMessageDetails);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    @Async
    public void sendMsgForHomeworkFinish(String userId, String userName, Integer homeworkId, String studentName, String subjectName) {
        try {
            String pkMessageDetailsId = UUID.randomUUID().toString();
            String url = " ";
            DingTalkActionCardBean actionCardBean = new DingTalkActionCardBean();
            actionCardBean.setTitle("作业批改");
            actionCardBean.setAgentId(DingTalkConstUtil.XINIAO_AGENT_ID);
            actionCardBean.setUserIds(userId);
            actionCardBean.setSingleTitle("去批改");
            actionCardBean.setSingleUrl(url);
            String markdown = MarkdownUtil.getMarkdown(
                    MarkdownUtil.getImage(IMAGE_URL),
                    MarkdownUtil.getTitle("作业通知", 5),
                    MarkdownUtil.getTitle("有一份作业等待你去批改哦!请在工作台中打开犀鸟完成批改", 0),
                    MarkdownUtil.getTitle(studentName + " " + subjectName, 6)
            );
            actionCardBean.setMarkdown(markdown);
            OapiMessageCorpconversationAsyncsendV2Response response = DingTalkMessageUtil.sendActionCardMsg(actionCardBean);
            Boolean ifSendSuccess = false;
            if (response.getErrcode() == 0) {
                ifSendSuccess = true;
            }
            Integer[] ids = {homeworkId};
            PkMessageDetails pkMessageDetails = getPkMessageDetails(userId, userName, true, Arrays.asList(ids));
            pkMessageDetails.setId(pkMessageDetailsId);
            pkMessageDetails.setIfSendSuccess(ifSendSuccess);
            pkMessageDetails.setMessageContent(String.format("作业批改通知: userId=%s,userName=%s,homeworkId=%s,studentName=%s,subjectName=%s",
                    userId,
                    userName,
                    homeworkId,
                    studentName,
                    subjectName));
            pkMessageDetails.setMessageUrl(url);
            pkMessageDetails.setMessageType(MessageTypeEnum.MESSAGE_HOMEWORK_FINISH);
            pkMessageDetailsMapper.insertSelective(pkMessageDetails);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private PkMessageDetails getPkMessageDetails(String userId, String userName, Boolean ifTeacher, List<Integer> pkLessonIds) {
        String ids = pkLessonIds.stream().map(id -> String.valueOf(id)).collect(Collectors.joining("],[", "[", "]"));
        PkMessageDetails pkMessageDetails = new PkMessageDetails();
        Date currentDate = new Date();
        pkMessageDetails.setUserId(userId);
        pkMessageDetails.setThirdPartyId(userId);
        pkMessageDetails.setThirdPartyType(ThirdPartyTypeEnum.DINGTALK);
        if (ifTeacher){
            pkMessageDetails.setUserIdentity(MessageUserIdentityEnum.TEACHER);
        }else{
            pkMessageDetails.setUserIdentity(MessageUserIdentityEnum.MASTER);
        }

        pkMessageDetails.setUserName(userName);
        pkMessageDetails.setIfReceiveConfirm(false);
        pkMessageDetails.setCreateTime(currentDate);
        pkMessageDetails.setIfReceiveConfirm(false);
        pkMessageDetails.setIfSendSuccess(false);
        pkMessageDetails.setPkLessonId(ids);
        return pkMessageDetails;
    }
}
